import { api } from '~/utils/ajax'
import { useMutate } from '~/utils/mutate'

export const clients = ref([])

export function getClients() {
  return api.get(`client`).then(data => {
    clients.value = data
  })
}

export function createClient(input) {
  return api.post(`client`, input).then(output => {
    const { client_secret } = output
    output.client_secret = ''
    clients.value.push(output)
    return { ...output, client_secret }
  })
}

export const mutation = useMutate(clients, 'client', { idField: 'client_id' })
